home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 1 / Gekikoh Dennoh Club Vol. 1 (Japan).7z / Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin / tools / ebsx130 / ebsx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  26.4 KB  |  1,130 lines

  1. /*
  2.  *  postSx.x
  3.  *
  4.  *  Author : D.N  kit.iizuka
  5.  *  Created: 1993 12/15(Wed)
  6.  */
  7.  
  8. #include "common.h"
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <method/Control_i.h>
  12. #include <method/Dialog_i.h>
  13. #include <method/Dos_i.h>
  14. #include <method/Graph_i.h>
  15. #include <method/Memory_i.h>
  16. #include <method/Task_i.h>
  17. #include <method/Window_i.h>
  18. #include <method/Event_i.h>
  19. #include <method/_methodSx.h>
  20. #include <method\methodsx.h>
  21.  
  22. /* #include <method\methodSx.h>
  23. #include <method\sxlib.h>
  24. */
  25. #define SXVERSION 0x110 /* SXのバージョンチェック用 */
  26. #define VERSTR "1.00"   /* バージョン番号 */
  27.  
  28. #define MAIN_DX 300  /* メインウインドウの横幅 */
  29. #define MAIN_DY 230  /* メインウインドウの縦幅 */
  30. #define MAIN_ID 49   /* メインウインドウの種類 */
  31. #define MAIN_OPT WC_GBOX /* メインウインドウの付属品 */
  32.  
  33. /* QueryError用 */
  34. #define rectQE Rect(10, 30, 240, 160)
  35.  
  36. /*
  37.  * 関数宣言
  38.  */
  39.  
  40. void SaveComLine();
  41. int MyIconify();
  42.  
  43. int PostMain(char *opt);
  44. void PostTini();
  45. /* void InitTable(); */
  46.  
  47. int        MainDraw(void);
  48. void    WhoAmI(void);
  49. int        PostMenuProc(void);
  50. int TableMenuProc(void);
  51. int LCCBtnProc();
  52. int ExecCommand();
  53. int FnameProc();
  54. int EscCancel(method_t *tm);
  55. int    InputFile(void);
  56. int Dropped();
  57. int        DrawDialog(void);
  58. int        CopyMidasi(void);
  59. /* int        CopyAll(void); */
  60. int        CopyBeneath(void);
  61. int        DispHonbun(int);
  62. int        DoSelect(void);
  63. int        SxBasic(void);
  64. void    MainLoop(void);
  65. int        Init(void);
  66. void    Tini(void);
  67. /* kenji  */ int    main( int , char *[] );
  68. int DoMenukensaku( void );
  69.  
  70. /* グローバル変数 各ファイル共通 */
  71. int        cdfile;
  72. int        tableMax;
  73. int        limit;
  74. unsigned int    indexpage , indexoff;    /* kenji suzuki */
  75. int        searchMode;
  76.  
  77. char        *tablePostNo[MAX_TABLE_POST_NO];    /* 項目名 */
  78. unsigned int    tableFilePos[ MAX_TABLE_POST_NO ]; /* kenji suzuki ファイルないの位置 */
  79.  
  80. /* 現在のモード 0 = ファイル未指定 1 = カタログファイルオープン中 2 = 文献ファイルオープン中(通常検索) */
  81. int        oprateMode;
  82.  
  83.  
  84. /* 外部参照 */
  85. /* extern unsigned short menupage_st;    */    /* メニューが始まるページ */
  86. /* extern unsigned short menupage_ed;    */    /* メニューが終わるページ */
  87.  
  88. /* グローバル変数 このファイルのみ */
  89. static char searchAddress[100];    /* 検索した住所 */
  90. char fname[258] = "\0";            /* ファイル名格納用 */
  91. char oldfname[258] = "\0";
  92. char title[32];
  93. char *bunkenFile;            /* 実際に開いたファイル名 */
  94. static int command = 0;            /* 現在処理中のコマンド */
  95.  
  96. /*
  97.  * 描画ルーチンリスト
  98.  */
  99. proc_list_t
  100.     mainDraw = {MainDraw, NULL /* リスト終了 */};
  101.  
  102. /*
  103.  * ウインドウ定義
  104.  */
  105. window_t mainWin = {
  106.     &mainDraw, (window *) NULL, (window *) -1, {0, 0, MAIN_DX, MAIN_DY},
  107.     "\@[電子ブック] 検索", 0, (MAIN_ID << 4) + MAIN_OPT, 0b1001
  108. };
  109.  
  110. /*
  111.  * 各種Methodの内容定義
  112.  */
  113. char menuStr[] = {
  114.     "^Hこのプログラムは..,"
  115.     "^Fファイルを開く,"
  116.     "~,"
  117.     "^W本文の全クローズ,"
  118.     "~,"
  119.     "^Iアイコン化,"
  120.     "^Q終了"
  121. };
  122. char menuStr2[] = {
  123.     " コピー,"
  124.     "~,"
  125.     "^A全選択,"
  126.     "^D全選択解除"
  127. };
  128.  
  129. m_menu_t
  130.     menuPost  = {{0, -20, 1024, 1024}, 0b0001, "\@電子ブック検索", (long) menuStr , NULL},    /* メイン用 */
  131.     menuTable = {{0, 0, 10, 10}      , 0b0001, 0 ,                 (long) menuStr2, NULL};    /* 表選択用(ここでのrectは適当な値) */
  132.  
  133. char address[200];
  134. m_text_t
  135.     addressm = {address, 190, {4, 10, 4 + 224 , 10 + 16}, 1, 0, 0, 0,
  136.         G_BLACK, G_WHITE, 0b101001, NULL, 1},
  137.     fnameTM = {        /* ksuzuki ファイル名入力用 */
  138.         fname, 90, {60, 60, 60 + 6*30, 60 + 12},
  139.         0, 0, 0, Point_t(0, 0), G_BLACK, G_WHITE,
  140.         0b01011, EscCancel, 0
  141.     };
  142.  
  143. char *titleLC[2] = {"\@実行", "\@中止"};
  144. point_t ptLC[2] = {Point_t(150, 128), Point_t(200, 128)};
  145. m_chrbtns_t loadCancelCBM = {
  146.     ptLC,        /* @配置左上座標の配列へ */
  147.     titleLC,    /* @文字列へのポインタの配列へ ※LASCII */
  148.     2,            /* @ボタン総個数 */
  149.     0,            /* @休止状態フラグ */
  150. };
  151.  
  152. m_control_t
  153.     search = {{242, 10 , 242 + 6*6 + X_STDBTN, 10  + DY_STDBTN}, 0, 0, 1, 0, "\@検索"},
  154.     select = {{300-100, 230-20, (300-100) + 6*8 + X_STDBTN, (230-20) + DY_STDBTN}, 0, 0, 1, 0, "\@選択"},
  155.     menuken = {{242, 34 , 242 + 6*6 + X_STDBTN, 34 + DY_STDBTN}, 0, 0, 1, 0, "\@メニュー"};
  156.  
  157. m_table_t
  158.     noSelect = {0, 0, 0, 0b01010, 1, 0, Point_t(4, 90), tablePostNo, NULL};
  159.  
  160. char *sxbCom[4] = {"SEARCH", "ZENKAKU", "HANKAKU", "QUIT"};
  161. m_sxbasic_t
  162.     sxbasic = {4, sxbCom, 0b0000};
  163. /* noSelect.tbValue */
  164.  
  165. /* kenji */
  166. char    *week2[] = { "\@前方一致", "\@後方一致", "\@完全一致"},
  167.     *week1[] = { "\@EB/EBXA", "\@EBG"};
  168.  
  169. m_udmenu_t
  170.     week2UDM = {3,10,week2, 1, 0,
  171.         Point_t(120,34) },
  172.     week1UDM = {2,10,week1, 1, 0,
  173.         Point_t(4,34) };
  174.  
  175. /*
  176.  * Method定義
  177.  */
  178. method_t
  179.     mMenu =    {NULL, m_MENU, (m_control_t *) &menuPost, PostMenuProc},
  180.     mTMenu =    {NULL, m_MENU, (m_control_t *) &menuTable, TableMenuProc},
  181.     mAddress = {NULL, m_STRING, (m_control_t *) &addressm, NULL},
  182.     mSearch =  {NULL, m_STDBTN, &search, NULL},
  183.     mSelect = {NULL, m_STDBTN, &select, DoSelect},
  184.     mMenuken = {NULL, m_STDBTN, &menuken, DoMenukensaku},
  185. /*    mZenkaku = {NULL, m_OTNBTN, &zenkaku, (proc_t) -1}, */
  186.     mSxBasic = {NULL, m_SXBASIC, (m_control_t *) &sxbasic, SxBasic},
  187.     mNoSelect ={NULL, m_TABLE, (m_control_t *) &noSelect, (proc_t) -1},
  188.     mWeek2UDM =    {NULL, m_UPDMENU, &week2UDM, (proc_t) -1}, /* kenji */
  189.     mWeek1UDM =    {NULL, m_UPDMENU, &week1UDM, (proc_t) -1}, /* kenji */
  190.     mDropDM =    {NULL, m_DRPDWN, NULL, Dropped},
  191.     mLCCBM =    {NULL, m_CHRBTNS, &loadCancelCBM, LCCBtnProc},
  192.     mFnameTM =    {NULL, m_STRING, &fnameTM, FnameProc},
  193.     mDialogDM =    {NULL, m_DRAWWIN, DrawDialog, (proc_t) -1},
  194.     /* Methodグループ */
  195. /*    *mgAll[] = {&mAddress, &mSxBasic, &mSearch, &mCopy, &mCopyBen, &mZenkaku , &mNoSelect, &mMenu     , &mWeekUDM , &mDropDM , NULL}; */
  196.     *mgAll[] = {&mAddress, &mSxBasic, &mSearch,         &mSelect , &mMenuken , &mNoSelect, &mWeek2UDM, &mWeek1UDM , &mMenu    , &mDropDM , NULL};
  197. method_t *dialogMG[] = {&mDialogDM, &mFnameTM, &mLCCBM, NULL};
  198.  
  199. /* 参考 t_query.c */
  200. /* QueryError を利用した疑似ダイアログの為の用意 */
  201.  
  202. int EventForQE(order_t order)
  203. {
  204.     switch (order.ev) {
  205.       case EV_CLOSEALL:
  206.       case EV_CLOSEWIN:
  207.         return order.ev;    /* そのままイベント内容を返す */
  208.     }
  209.     /* 他のイベントは全て無視 */
  210.     return 0;
  211. }
  212.  
  213.  
  214. /*
  215.  * 描画関数定義
  216.  */
  217. void DrawAddress()
  218. {
  219.     char num[ 28 ];
  220.     int pen = GMPenMode(G_BACK);
  221.  
  222.     if (kouhocount > 0)
  223.     {
  224.         ULUsingL( num , (int)kouhocount , 5 );
  225.         strcat( num , " 件" );
  226.     } else {
  227.         strcpy( num , " 一致する項目はありません" );
  228.     };
  229.     GMFillRect(&Rect(60, 66, 1024, 66 + 12));
  230.     GMPenMode(pen);
  231.     ULBlackStrZ( num , Point_t(60, 66));
  232. }
  233.  
  234. int MainDraw()
  235. {
  236.     ULD3LineH(Point_t(0, 58), Point_t(1024, 0), 1);
  237. /*    ULBlackStrZ("(", Point_t(4, 66));
  238.     ULBlackStrZ(")", Point_t(182, 66)); */
  239.     ULBlackStrZ("検索結果:", Point_t(4, 66));
  240.     DrawAddress();
  241.     GMPenMode(G_BACK);
  242.     GMBackColor(G_LGRAY);
  243.     GMFillRect(&Rect(4 - 2, 90 - 2, 1024, 1024));    /* 表を消す */
  244.     return 0;
  245. }
  246.  
  247.  
  248. /*
  249.  * Methodのコールバック
  250.  */
  251. /* メニュー処理 */
  252. void WhoAmI()
  253. {
  254.     GMShadowStrZ( "このプログラムは・・・", Point_t(64,4) );
  255.     ULBlackStrZ( "このプログラムは、電子ブックを", Point_t(20,36) );
  256.     ULBlackStrZ( "検索します。", Point_t(20,50) );
  257.     ULBlackStrZ( "           version 1.30 : 鈴木 健児", Point_t(8,68) );
  258.     DMBeep(2);
  259. }
  260. int PostMenuProc()
  261. {
  262.     int i , j , max , value;
  263.  
  264.     switch (menuPost.mValue) {
  265.       case 1:
  266.         ULWhoAmI(WhoAmI);
  267.         break;
  268.       case 2:
  269.         InputFile();
  270.         break;
  271.       case 4:
  272.         TskAllClose();
  273.         break;
  274.       case 6:
  275.         if (MyIconify() < 0)
  276.             return EV_CLOSEALL;
  277.         break;
  278.       case 7:
  279.         return EV_CLOSEALL;
  280.     }
  281.     return 1;
  282. }
  283.  
  284. int TableMenuProc()
  285. {
  286.     int i , j , max , value;
  287.  
  288.     switch (menuTable.mValue) {
  289.       case 1:
  290.         CopyMidasi( );
  291.         break;
  292.       case 3:
  293.         value = 0;
  294.         i = 1;            /* マスク */
  295.         if( noSelect.tbMax > 32 )
  296.         {
  297.             max = 32;
  298.         } else {
  299.             max = noSelect.tbMax;
  300.         };
  301.         for(j=0;j<max;j++)    /* 1~32行目を調べる */
  302.         {
  303.             value += i;
  304.             i = i << 1;    /* マスクを左にシフト */
  305.         }
  306.         noSelect.tbValue = value;
  307.         if( noSelect.tbMax > 32 )    /* 32行目以降を調べる */
  308.         {
  309.             for(j=32;j<(noSelect.tbMax);j++)    /* 1~32行目を調べる */
  310.             {
  311.                 *(tablePostNo[ j ]) = 1;
  312.             };
  313.         };
  314.         ReinitTBM(&mNoSelect);
  315.         SetWinGraph(&mainWin);
  316.         DrawMethod(&mNoSelect);
  317.         break;
  318.       case 4:
  319.         noSelect.tbValue = 0;
  320.         if( noSelect.tbMax > 32 )    /* 32行目以降を調べる */
  321.         {
  322.             for(j=32;j<(noSelect.tbMax);j++)    /* 1~32行目を調べる */
  323.             {
  324.                 *(tablePostNo[ j ]) = 0;
  325.             };
  326.         };
  327.         ReinitTBM(&mNoSelect);
  328.         SetWinGraph(&mainWin);
  329.         DrawMethod(&mNoSelect);
  330.         break;
  331.     }
  332.     return 1;
  333. }
  334.  
  335. /* メニュー検索用のウィンドウを起動 */
  336. int DoMenukensaku( )
  337. {
  338.     int stat;
  339.  
  340.     if( mpagenumber != 0 )
  341.     {
  342.         stat = printout2( 1 , (mpagenumber-1)*0x800 );
  343.         if( stat == 2 )
  344.         {
  345.             return( 65535 );
  346.         };
  347.     };
  348.  
  349.     return( 1 );
  350. }
  351.  
  352. /*
  353.  * ファイルアイコンがウインドウにドロップされると
  354.  * ESC+fと同等の処理をアイコンのファイル名に対して行う
  355.  */
  356. int Dropped()
  357. {
  358.     char sbuf[258];
  359.     if (ULGetDroppedFile(sbuf) <= 0) {
  360.         QueryError(1, "ファイル名が\0分からんぎゃあ(名古屋弁)\0\0" , (proc_t) EventForQE, &mainWin, &rectQE);
  361.         return -1;
  362.     };
  363.  
  364.     TSEndDrag(0);
  365.     strcpy(oldfname, fname);
  366.     strcpy(fname, sbuf);
  367.     command = 'F';
  368.     ExecCommand();
  369.     DrawMethod(&mAddress);
  370.     return 1; /* このMethodの処理をした */
  371. }
  372.  
  373. /*
  374.  * ESCでキャンセルするフィルタ関数
  375.  */
  376. static int flgCancel = false;
  377. int EscCancel(method_t *tm)
  378. {
  379.     int key = KeyOfEvent(&curEvRec);
  380.     flgCancel = false;
  381.     if (key == '\033') { /* ESCコード? */
  382.         flgCancel = true;
  383.         return 2;    /* このMethodの入力 */
  384.     }
  385.     return 0;    /* フィルタは何もしていない */
  386. }
  387.  
  388. /*
  389.  * 疑似ダイアログ描画関数
  390.  */
  391. rect imgDialog = {20, 20, 280, 160},
  392.      lcBtns = {150-14, 128-4, 236+14, 128+DY_STDBTN+8};
  393. static char
  394.     *fsMsg = "フォントサイズ変更:",
  395.     *fMsg = "ロードファイル名を入力",
  396.     *wMsg = "新規保存ファイル名を入力";
  397. int DrawDialog()
  398. {
  399.     char *msg = NULL;
  400.     GMShadowRect(&lcBtns);
  401.     switch (command) {
  402.       case 'F':
  403.         msg = fMsg; break;
  404.     }
  405.     if (msg)    /* 現在のコマンドに応じてメッセージを添える */
  406.         GMShadowStrZ(msg, Point_t(65, 40));
  407.     /* それぞれのコマンドでもっと描かなければならないならここでかく */
  408. /*    switch (command) {
  409.       case 'F':
  410.         ULBlackStrZ("X:", Point_t(30, 60+2));
  411.         ULBlackStrZ("Y:", Point_t(30, 88+2));
  412.         break;
  413.     } */
  414.     return 0;
  415. }
  416.  
  417. int    ShowErr( char *fname )
  418. {
  419.     int    len;
  420.     char mesQE[ 260 ] = "ファイルが開けません";
  421.             /*   01234567890123456789012 1 */
  422.  
  423.     mesQE[ 20 ] = '\0';    
  424.     strcpy( &mesQE[ 21 ] , fname );
  425.     len = strlen( fname );
  426.     mesQE[ 21 + len     ] = '\0';
  427.     mesQE[ 21 + len + 1 ] = '\0';
  428.  
  429.     QueryError(1, mesQE , (proc_t) EventForQE, &mainWin, &rectQE);
  430.  
  431.     return( 0 );
  432. }
  433.  
  434. /*
  435.  * コマンド実行
  436.  */
  437. int ExecCommand()
  438. {
  439.   int ret = false;
  440.   int stat;
  441.   int len;
  442.   char    wintitle[ 40 ];
  443.  
  444.   if (!flgCancel) {     /* キャンセルでは終了していない */
  445.     switch (command) {
  446.       case 'F':        /* 文献ファイル入力 */
  447.         /* パス名の解析 */
  448.         stat = checkFile( fname );
  449.         if( stat == 1 )        /* カタログファイル */
  450.         {
  451.             stat = read_catalog( fname );
  452.             if( stat >= 0 )
  453.             {
  454.                 oprateMode = 1;
  455.                 noSelect.tbMax = tableMax;
  456.                 noSelect.tbValue = 0;
  457.                 ReinitTBM(&mNoSelect);
  458.                 SetWinGraph(&mainWin);
  459.                 strcpy( wintitle+1 , "[カタログ]" );
  460.                 wintitle[ 0 ] = 10;
  461.                 WMTitleSet( mainWin.wptr , wintitle );
  462.                 SleepMethod( &mMenuken , 1 );
  463.                 DrawMethod(&mNoSelect);
  464.                 DrawAddress();
  465.                 EMDeCross(); 
  466.             } else {
  467.                 ShowErr( fname );
  468.                 flgCancel = true;
  469.                 ret = true;
  470.             };
  471.         } else if( stat == 3 )        /* カタログファイル */
  472.         {
  473.             stat = read_catalogEP( fname );
  474.             if( stat >= 0 )
  475.             {
  476.                 oprateMode = 1;
  477.                 noSelect.tbMax = tableMax;
  478.                 noSelect.tbValue = 0;
  479.                 ReinitTBM(&mNoSelect);
  480.                 SetWinGraph(&mainWin);
  481.                 strcpy( wintitle+1 , "[カタログ]" );
  482.                 wintitle[ 0 ] = 10;
  483.                 WMTitleSet( mainWin.wptr , wintitle );
  484.                 SleepMethod( &mMenuken , 1 );
  485.                 DrawMethod(&mNoSelect);
  486.                 DrawAddress();
  487.                 EMDeCross(); 
  488.             } else {
  489.                 ShowErr( fname );
  490.                 flgCancel = true;
  491.                 ret = true;
  492.             };
  493.         } else if(( stat == 2 ) || ( stat == 4 ))    /* 文献ファイル */
  494.         {
  495.             stat = CdFileOpen( fname , oldfname );
  496.             if( stat >= 0 )
  497.             {
  498.                 /* ウィンドウタイトルの作成 */
  499.                 if( w_key == 1 )
  500.                 {
  501.                     stat = get_titleEP( fname , title );
  502.                 } else {
  503.                     stat = get_title( fname , title );
  504.                 };
  505.                 if( stat == 0 )
  506.                 {
  507.                     if( e_key == 0 )
  508.                     {
  509.                         convJis( title );
  510.                     };
  511.                     wintitle[ 1 ] = '[';
  512.                     wintitle[ 2 ] = '\0';
  513.                     strcat( wintitle+1 , title );
  514.                     strcat( wintitle+1 , "] 検索" );
  515.                     wintitle[ 0 ] = strlen( title ) + 7;
  516.                 } else {
  517.                     strcpy( wintitle+1 , "[電子ブック] 検索" );
  518.                     wintitle[ 0 ] = 17;
  519.                 };
  520.                 WMTitleSet( mainWin.wptr , wintitle );
  521.  
  522.                 InitTable();
  523.                 oprateMode = 2;
  524.                 noSelect.tbMax = tableMax;
  525.                 noSelect.tbValue = 1;
  526.                 ReinitTBM(&mNoSelect);
  527.                 SetWinGraph(&mainWin);
  528.  
  529.                 if( mpagenumber != 0 )
  530.                 {
  531.                     AwakeMethod( &mMenuken , 1 );
  532.                 } else {
  533.                     SleepMethod( &mMenuken , 1 );
  534.                 };
  535.                 DrawMethod(&mNoSelect);
  536.                 DrawAddress();
  537.                 EMDeCross(); 
  538.                 bunkenFile = fname;
  539.             } else {
  540.                 ShowErr( fname );
  541.                 strcpy(fname , oldfname );
  542.                 flgCancel = true;
  543.                 ret = true;
  544.             };
  545.         } else {
  546.             flgCancel = true;
  547.             ret = true;
  548.         };
  549.         break;
  550.     }
  551.   }
  552. /*  MMHdlDispose(tex); */
  553.   flgCancel = false; 
  554.   return ret;
  555. }
  556.  
  557. /*
  558.  * 実行/中止ボタンの処理
  559.  */
  560. int LCCBtnProc()
  561. {
  562.     if (2 == loadCancelCBM.cbValue) /* 中止ボタン */
  563.         flgCancel = true;
  564.     else
  565.         flgCancel = false;
  566.  
  567. /*    if (command != 'F')    */
  568.         return FnameProc();
  569. /*    ExecCommand();        */    /* 実行ボタンが押された(文字大調節) */
  570. /*    CloseQuery(&mainWin, false);
  571.     ActivateTMethod(&mAddress, &mainWin);
  572.     DrawWindow(&mainWin);
  573. */    return 1;
  574. }
  575.  
  576. /*
  577.  * ファイル名の入力の処理
  578.  */
  579. int FnameProc()
  580. {
  581.     int flg = flgCancel;
  582.     SaveMethod(&mFnameTM);
  583.     CloseQuery(&mainWin, flg);
  584.     command = 'F';
  585.     ExecCommand();            /* ファイル名の入力が終了 */
  586. /*    if (!flg)    */
  587.         DrawWindow(&mainWin);
  588.     ActivateTMethod(&mAddress, &mainWin);
  589.  
  590.     return 1;
  591. }
  592.  
  593. int InputFile()
  594. {
  595.     strcpy(oldfname, fname);    /* 現在開いているファイル名を保存 */
  596.     command = 'F';
  597.     OpenQuery(&mainWin, &imgDialog, dialogMG);
  598.     ClipOnQuery(&mainWin, false);
  599.     SetSelectTM(&mFnameTM);
  600.     ActivateTMethod(&mFnameTM, &mainWin); /* ファイル名入力開始 */
  601.     ClipOnContents(&mainWin);
  602.     if (command)
  603.         return 1;    /* textに対するこのキー入力は無視して良い */
  604.     return 0; /* キー入力処理を続けて下さい */
  605. }
  606.  
  607. int DoSelect( void )
  608. {
  609.     int line;
  610.     int len;
  611.     int stat;
  612.     int i,j;
  613.     char    fname2[ 258 ];
  614.     char    path[ 10 ];
  615.  
  616.     if( oprateMode == 1 )    /* 文献ファイルのオープン */
  617.     {
  618.         line = 0;
  619.         i = 1;            /* マスク */
  620.         for(j=0;j<32;j++)    /* 1~32行目を調べる */
  621.         {
  622.             if( (i & noSelect.tbValue) > 0 )
  623.             {
  624.                 line = j + 1;
  625.             };
  626.             i = i << 1;    /* マスクを左にシフト */
  627.         }
  628.         if( noSelect.tbMax > 32 )    /* 32行目以降を調べる */
  629.         {
  630.             for(j=32;j<(noSelect.tbMax);j++)    /* 1~32行目を調べる */
  631.             {
  632.                 if( *(tablePostNo[ j ]) == 1 )
  633.                 {
  634.                     line = j + 1;
  635.                 };
  636.             };
  637.         };
  638.         if( line > 0 )
  639.         {
  640.             if( w_key == 1 )
  641.             {
  642.                 stat = get_pathEP( fname , line , path );
  643.                 strcpy(oldfname, fname);
  644.                 /* ファイル名の作成 */
  645.                 fname2[ 0 ] = 0;
  646.                 strncpy( fname2 , fname , 3 );    /* ドライブ名 「F*\」 */
  647.                 fname2[ 3 ] = 0;
  648.                 strcat( fname2 , path );    /* ディレクトリ名 */
  649.                 strcat( fname2 , "\\data\\honmon" );    /* ファイル名 「\START」*/
  650.             } else {
  651.                 stat = get_path( fname , line , path );
  652.                 strcpy(oldfname, fname);
  653.                 /* ファイル名の作成 */
  654.                 fname2[ 0 ] = 0;
  655.                 strncpy( fname2 , fname , 3 );    /* ドライブ名 「F*\」 */
  656.                 fname2[ 3 ] = 0;
  657.                 strcat( fname2 , path );    /* ディレクトリ名 */
  658.                 strcat( fname2 , "\\start" );    /* ファイル名 「\START」*/
  659.             };
  660.             if( stat >= 0 )
  661.             {
  662.                 fname[ 0 ] = 0;
  663.                 strcpy( fname , fname2 );
  664.                 command = 'F';
  665.                 ExecCommand();
  666.                 ActivateTMethod(&mAddress, &mainWin);
  667.             } else {
  668.                 ShowErr( fname2 );
  669.             };
  670.         };
  671.     } else if( oprateMode == 2 )
  672.     {
  673.         i = 1;            /* マスク */
  674.         for(j=0;j<32;j++)    /* 1~32行目を調べる */
  675.         {
  676.             if( (i & noSelect.tbValue) > 0 )
  677.             {
  678.                 stat = DispHonbun( j + 1 );
  679.             };
  680.             i = i << 1;    /* マスクを左にシフト */
  681.         }
  682.         if( noSelect.tbMax > 32 )    /* 32行目以降を調べる */
  683.         {
  684.             for(j=32;j<(noSelect.tbMax);j++)    /* 1~32行目を調べる */
  685.             {
  686.                 if( *(tablePostNo[ j ]) == 1 )
  687.                 {
  688.                     stat = DispHonbun( j + 1 );
  689.                 };
  690.             };
  691.         };
  692.     };
  693.  
  694.     return( 1 );
  695. }
  696.  
  697. int DispHonbun( int line )
  698. {
  699.     int stat;
  700.  
  701.     if( oprateMode == 2 )
  702.     {
  703.         if( tablePostNo[ line-1 ] != NULL && tableFilePos[ line-1 ] != NULL )
  704.         {
  705.             stat = printout2( line-1 , tableFilePos[ line-1 ] );
  706.             if( stat == 2 )
  707.             {
  708.                 return( 65535 );
  709.             };
  710.         };
  711.     };
  712.     return( 1 );
  713. }
  714.  
  715.  
  716. /* 見出しをテキストスクラップへ */
  717. int CopyMidasi()
  718. {
  719.     char *st;
  720.     char *buff, *sstr, *dstr;
  721.     int siz = 0, i;
  722.     int j,k;
  723.  
  724.     if (0 == noSelect.tbMax) {
  725.         QueryError(1, "まず検索して下さい!\0\0" , (proc_t) EventForQE, &mainWin, &rectQE);
  726.         return 1;
  727.     }
  728.     /* 必要なバッファサイズを割り出す */
  729.     i = 1;            /* マスク */
  730.     for(j=0;j<32;j++)    /* 1~32行目を調べる */
  731.     {
  732.         if( (i & noSelect.tbValue) > 0 )
  733.         {
  734.             siz += 8 + strlen( tablePostNo[ j ] );  /* 8はさばよみ */
  735.         };
  736.         i = i << 1;    /* マスクを左にシフト */
  737.     }
  738.     if( noSelect.tbMax > 32 )    /* 32行目以降を調べる */
  739.     {
  740.         for(j=32;j<(noSelect.tbMax);j++)    /* 1~32行目を調べる */
  741.         {
  742.             if( *(tablePostNo[ j ]) == 1 )
  743.             {
  744.                 st = tablePostNo[j] + 1;
  745.                 siz += 8 + strlen( st );  /* 8はさばよみ */
  746.             };
  747.         };
  748.     };
  749.     if ((buff = _ULMALLOC(siz + 1)) == NULL) {
  750.         QueryError(1, "作業用メモリが足りません!\0\0" , (proc_t) EventForQE, &mainWin, &rectQE);
  751.         return 1;
  752.     }
  753.     /* 文字列を作り上げる */
  754.     dstr = buff;
  755.     i = 1;            /* マスク */
  756.     for(j=0;j<32;j++)    /* 1~32行目を調べる */
  757.     {
  758.         if( (i & noSelect.tbValue) > 0 )
  759.         {
  760.             sstr = tablePostNo[j];
  761.             k = strlen( sstr );
  762.             strcpy( dstr , sstr );
  763.             dstr += k;
  764.             *dstr++ = 0xd;
  765.             *dstr++ = 0xa;
  766.         };
  767.         i = i << 1;    /* マスクを左にシフト */
  768.     }
  769.     if( noSelect.tbMax > 32 )    /* 32行目以降を調べる */
  770.     {
  771.         for(j=32;j<(noSelect.tbMax);j++)    /* 1~32行目を調べる */
  772.         {
  773.             if( *(tablePostNo[ j ]) == 1 )
  774.             {
  775.                 sstr = tablePostNo[j] + 1;
  776.                 k = strlen( sstr );
  777.                 strcpy( dstr , sstr );
  778.                 dstr += k;
  779.                 *dstr++ = 0xd;
  780.                 *dstr++ = 0xa;
  781.             };
  782.         };
  783.     };
  784.     *dstr = '\0';
  785.     ULStrToTMScrap(buff);
  786.     _ULFREE(buff);
  787.     return 1;
  788. }
  789.  
  790. /* SX-BASICで送信された時 */
  791. int SxBasic()
  792. {
  793. /*    char **com, **com2;
  794.     switch (sxbasic.sxbValue) {
  795.       case 1: */    /* SEARCH */
  796.     /*    com = sxbasic.sxbCommand;
  797.         com2= sxbasic.sxbCommand2;
  798.         if (com[0][6])    */            /* comにオプションもついていた */
  799.     /*        strncpy(address, &com[0][6], 100);
  800.         else if (!com2)        */        /* com2に格納されていた */
  801. /*            strncpy(address, *com2, 100);
  802.         ULStrAdjustLeft(address);
  803.         ChangeTextTM(&mAddress, address);
  804.         SetSelectTM(&mAddress);
  805.         return (int) &mAddress;        *//* これで十分実行してくれる */
  806.  /*      case 2: */    /* ZENKAKU */
  807. /*        ValueSetCM(&zenkaku, 1); */
  808.  /*        break;
  809.       case 3: */    /* HANKAKU */
  810. /*        ValueSetCM(&zenkaku, 0); */
  811.     /*    break; 
  812.       case 4: */    /* QUIT */
  813. /*        return EV_CLOSEALL;
  814.     } */
  815.     return 1;
  816. }
  817.  
  818. /* 表選択用メニューが出る範囲を変更 */
  819. int    ChRectTMenu( void )
  820. {
  821.     GetWholeRectTBM(&noSelect, &menuTable.mRect);
  822.     ChainAMethod( NULL , &mainWin , &mTMenu );        /* 先頭に登録 */
  823.  
  824.     return( 0 );
  825. }
  826.  
  827. /*  */
  828. int    MoveBtn( void )
  829. {
  830.     point_t size = ULGetSizeWindow(mainWin.wptr);
  831.  
  832.     size = (point_t)ULAddPoint( size , Point_t( -100 , -20 ) );
  833.     select.cRect = Rect( Pt_x(size), Pt_y(size), Pt_x(size) + 6*8 + X_STDBTN, Pt_y(size) + DY_STDBTN );
  834.     CMMove( select.cHdl , size );
  835.  
  836.     return( 0 );
  837. };
  838.  
  839. /* 結果表示用表選択Methodの大きさを変える */
  840. void InViewTable()
  841. {
  842.     point_t size = ULGetSizeWindow(mainWin.wptr),
  843.         a_col_siz = GetASizeTBM(&noSelect);
  844.     noSelect.tbHMax = (Pt_x(size) - Pt_x(noSelect.tbPt) - DY_SLDVOL) / Pt_x(a_col_siz) - 2;
  845.     noSelect.tbVMax = (Pt_y(size) - Pt_y(noSelect.tbPt) - DY_SLDVOL) / Pt_y(a_col_siz);
  846. }
  847.  
  848. /* 結果表示用表選択Methodの大きさを変え、表示し直す領域を設定する
  849.  * 実際には直後にUPDATEが起こるので描き直しはしない */
  850. point_t preWinSize;
  851. void InViewTable2()
  852. {
  853.     point_t tbpt, p1, p2, pp1, pp2, pwsz, wsz = ULGetSizeWindow(mainWin.wptr);
  854.     int top = GetTopTBM(&noSelect);
  855.     rect rct, prct, tr;
  856.  
  857.     /* 計算前の値を持っておく(以前のウインドウの大きさの時の値) */
  858.     GetRect2TBM(&noSelect, noSelect.tbVMax - 1, &prct);
  859.  
  860.     InViewTable();
  861.     ReinitTBM(&mNoSelect);
  862.     SetTopTBM(&noSelect, top);
  863.  
  864.     SetWinGraph(&mainWin);
  865.     if (GetTopTBM(&noSelect) < top) {
  866.         /* 大きくなりすぎて表示再上値が小さくなった → 全て描き直す */
  867.         GetWholeRectTBM(&noSelect, &rct);
  868.         *(point_t *) &rct.left = GMLocalToGlobal(*(point_t *) &rct.left);
  869.         *(point_t *) &rct.right = GMLocalToGlobal(*(point_t *) &rct.right);
  870.         /* 表全体の大きさを得、それをグローバル座標系に直した */
  871.         WMAddRect(&rct);
  872.     }
  873.     /* 表の右辺と底辺付近をアップデート領域にする */
  874.     GetRect2TBM(&noSelect, noSelect.tbVMax - 1, &rct);
  875.     tbpt = GMLocalToGlobal(noSelect.tbPt);
  876.     p1 = GMLocalToGlobal(Pt_t(rct.left, rct.top));
  877.     p2 = GMLocalToGlobal(Pt_t(rct.right, rct.bottom));
  878.     pp1 = GMLocalToGlobal(Pt_t(prct.left, prct.top));
  879.     pp2 = GMLocalToGlobal(Pt_t(prct.right, prct.bottom));
  880.     pwsz = GMLocalToGlobal(preWinSize);
  881.         preWinSize = wsz;
  882.     wsz = GMLocalToGlobal(wsz);
  883.     /* 横 */
  884.     if (Pt_y(pwsz) < Pt_y(wsz))
  885.         /* 前より幅は広くなった */
  886.         tr = Rect(Pt_x(tbpt)-2, Pt_y(pp1)-2, Pt_x(pwsz) - 18, Pt_y(pwsz));
  887.     else
  888.         /* 前より幅は狭くなった */
  889.         tr = Rect(Pt_x(tbpt)-2, Pt_y(p1)-2, Pt_x(wsz) - 18, Pt_y(wsz));
  890.     WMAddRect(&tr);
  891.     /* 縦 */
  892.     if (Pt_x(pwsz) < Pt_x(wsz))
  893.         /* 前より幅は広くなった */
  894.         tr = Rect(Pt_x(pp2) - 12, Pt_y(tbpt)-2, Pt_x(pwsz), Pt_y(pwsz) - 18);
  895.     else
  896.         /* 前より幅は狭くなった */
  897.         tr = Rect(Pt_x(p2) - 12, Pt_y(tbpt)-2, Pt_x(wsz), Pt_y(wsz) - 18);
  898.     WMAddRect(&tr);
  899.     /* 18 はグローボックスまで書き直したくないので */
  900.     /* 12 はさば読みで多めに領域を設定したいので */
  901.  
  902.  
  903.     /* 表選択用メニューが出る範囲を変更 */
  904.     UnchainAMethod( &mTMenu );    /* いったんチェインをはずす */
  905.     ChRectTMenu( );
  906.     MoveBtn( );
  907. }
  908.  
  909.  
  910. void MainLoop()
  911. {
  912.     char エラーメッセージ[100];
  913.     short エラーが起こった = false;
  914.     order_t order = {0};
  915.     char    workbuf[ 80 ];
  916.  
  917.     preWinSize = ULGetSizeWindow(mainWin.wptr);
  918.     while (true) {
  919.         order.ev = MayIHelpYou();
  920.         switch (order.ev) {
  921.           case EV_WINZMIN:
  922.           case EV_WINZMOUT:
  923.           case EV_WINGROW:
  924.             InViewTable2();
  925.             break;
  926.           case EV_ICONIFY:
  927.             if (MyIconify() < 0)
  928.                 return;
  929.             break;
  930.           case EV_SAVE:
  931.             SaveComLine();
  932.             break;
  933.           case EV_EXITTSK:
  934.             if( curEvRec.what2 == EXITTSK )
  935.             {
  936.         /*        int counter;
  937.                 counter = maxTskTable;
  938.                 while( --counter >= 0 )
  939.                 {
  940.                     if( tskTable[ counter ] == curEvRec.whom );
  941.                     {
  942.                 ULError_int( tskTable[ counter ] );
  943.                         tskTable[ counter ] == 0;
  944.                     };
  945.                 };
  946.         */    };
  947.             break;
  948.           case EV_NOTICEENDTSK:    /* ken */
  949.             break;
  950.           case EV_CLOSEALL:
  951.           case EV_CLOSEWIN:
  952.             SaveComLine();
  953.             return;                /* 終了指令ならメインループ終了 */
  954.           case EV_UNDEFINED:
  955. /*            if( oprateMode > 1 )
  956.             {
  957.                 if(( curEvRec.what == E_SYSTEM1 ) || ( curEvRec.what == E_SYSTEM2 ))
  958.                 {
  959.                     if( curEvRec.what2 == NOTICEEJECT )
  960.                     {
  961.                         DMError( 1, "イジェクト" );
  962.                     };
  963.                     if( curEvRec.what2 == DISKINSERT )
  964.                     {
  965.                         DMError( 1, "インサート" );
  966.                     };
  967.                 };
  968.             };
  969. */            break;
  970.           default:
  971.             if (order.mth == &mAddress
  972.              || order.mth == &mSearch) {
  973.                 SaveMethod(&mAddress);
  974.                 if( oprateMode != 2 )
  975.                 {
  976.                     QueryError(1, "文献ファイルを\0指定してください\0\0" , (proc_t) EventForQE, &mainWin, &rectQE);
  977.                     break;
  978.                 }
  979.  
  980.                 if (!address[0]) {
  981.                     QueryError(1, "検索する文字列を\0入力して下さい !!\0\0" , (proc_t) EventForQE, &mainWin, &rectQE);
  982.                     break;
  983.                 }
  984.                 EMEnCross(0);
  985.                 searchMode = week2UDM.umValue;
  986.                 e_key = week1UDM.umValue - 1;
  987.                 InitTable();
  988.                 Eb_Main(address);    /* リターンキーか, 検索ボタンで検索開始 */
  989.                 if (エラーが起こった) {
  990.                     ULError_str("eb_sx.x:", エラーメッセージ);
  991.                     noSelect.tbMax = 0;
  992.                     noSelect.tbValue = 0;
  993.                 } else {
  994.                     noSelect.tbMax = tableMax;
  995.                     noSelect.tbValue = 0;
  996.     strcpy( workbuf , address );
  997.     menuStr[ 10 ] = workbuf;
  998. /* */
  999.                 }
  1000.                 ReinitTBM(&mNoSelect);
  1001.                 SetWinGraph(&mainWin);
  1002.                 DrawMethod(&mNoSelect);
  1003.                 DrawAddress();
  1004.                 EMDeCross();
  1005.             }
  1006.         }
  1007.     }
  1008. }
  1009.  
  1010. int Init()
  1011. {
  1012.     /* 文字列テーブルを初期化 */
  1013. /*    InitTable(); */
  1014.     tableMax = 0;
  1015.     /* 結果表示部分を補正 */
  1016.     InViewTable();
  1017.     /* 検索住所をクリア */
  1018.     searchAddress[0] = '\0';
  1019.     kouhocount = 0;
  1020.     return 0;
  1021. }
  1022.  
  1023. void Tini()
  1024. {
  1025. /*     PostTini(); */
  1026. }
  1027.  
  1028. rect maxmin = {MAIN_DX, MAIN_DY, 740, 500};
  1029. int main(int argc, char *argv[])
  1030. {
  1031.     int i;
  1032.     unsigned char *argv0;
  1033.     argv0 = (unsigned char *) argv[0];
  1034.  
  1035. #ifdef SXVERSION
  1036.     if (SXVERSION > SXVer()) {
  1037.         QueryError(1,"SX-Window system の\0バージョンが古すぎます(1.10以上)\0\0" , (proc_t) EventForQE, &mainWin, &rectQE);
  1038.         return( 0 );
  1039.     }
  1040. #endif /* SXVERSION */
  1041.  
  1042.     /* コマンドライン判定. 余り使われないであろうから簡単にしてある */
  1043.     for (i = 1; i < argc; i++) {
  1044.         switch (argv[i][0]) {
  1045.           case '/':
  1046.           case '-':
  1047.             if( ('A' == argv[i][1]) || ('a' == argv[i][1]) )
  1048.             {
  1049.                 a_key = 1;
  1050.                 week2UDM.umValue = 3;
  1051.             } else if( ('R' == argv[i][1]) || ('r' == argv[i][1]) )
  1052.             {
  1053.                 r_key = 1;
  1054.                 week2UDM.umValue = 2;
  1055.             } else if( ('E' == argv[i][1]) || ('e' == argv[i][1]) )
  1056.             {
  1057.                 e_key = 1;
  1058.                 week1UDM.umValue = 2;
  1059.             } else if( ('F' == argv[i][1]) || ('f' == argv[i][1]) )
  1060.             {
  1061.                 ULStrcpy( fname , &argv[i][2] );
  1062.             } else if( ('S' == argv[i][1]) || ('S' == argv[i][1]) )
  1063.             {
  1064.                 ULStrcpy( address , &argv[i][2] );
  1065. /*            } else if( 'w' == argv[i][1])
  1066.             {
  1067.                 ;
  1068. */            };
  1069.             break;
  1070.           default:
  1071.             ULStrcpy(address, argv[i]);
  1072.             break;
  1073.         }
  1074.     }
  1075.  
  1076.     if (isIconified())
  1077.         if (MyIconify() < 0)
  1078.             Tini();
  1079.  
  1080.     if (OpenWindow(&mainWin, -100)) {
  1081.         ULError( "ウインドウさえ開きません" );
  1082.         return(1);
  1083.     }                            /* ウインドウを開く */
  1084.     if (Init() < 0)                        /* 初期化 */
  1085.         return(0);
  1086.     oprateMode = 0;
  1087.  
  1088. /*    maxTskTable = 0; */
  1089.  
  1090. /*    CdFileOpen( ); */
  1091.     SetWinGrowSize(&mainWin, &maxmin);    /* ウインドウの最大最小大きさを指定 */
  1092.     ChainMethodIn(&mainWin, mgAll);        /* Methodを登録する */
  1093.  
  1094.     ChRectTMenu( );                /* 後から表選択用メニューMethodを登録 */
  1095.     SleepMethod( &mMenuken , 1 );
  1096.  
  1097.     if( a_key == 1 )
  1098.     {
  1099.         week2UDM.umValue = 3;
  1100.     };
  1101.     if( r_key == 1 )
  1102.     {
  1103.         week2UDM.umValue = 2;
  1104.     };
  1105.     if( e_key == 1 )
  1106.     {
  1107.         week1UDM.umValue = 2;
  1108.     };
  1109.  
  1110.     SetSelectTM(&mAddress);                /* 初期住所をセレクト */
  1111.  
  1112.     if( fname[ 0 ] != NULL )
  1113.     {
  1114.         command = 'F';
  1115.         ExecCommand();
  1116.     };
  1117.     MainLoop();                    /* メインループ */
  1118.     UnchainAMethod( &mTMenu );            /* 先に表選択メニューMethodをはずす */
  1119.     UnchainMethod();                /* Methodを登録から外す */
  1120.     CloseWindow(&mainWin);                /* ウインドウを閉じる */
  1121.     InitTable();
  1122.     Tini();
  1123.     if(( oprateMode == 2 ) || ( oprateMode == 4 ))
  1124.     {
  1125.         CdFileClose( );
  1126.     };
  1127.  
  1128.     return( 0 );
  1129. }
  1130.